import Taro from "@tarojs/taro";

export const baseUrl = "https://chenyoukj.cn";
// export const baseUrl = "http://139.9.122.3:8088";

const http = {
  get() {},
  post(url, data) {
    return new Promise(resolve => {
      Taro.request({
        url: baseUrl + "/append" + url,
        method: "POST",
        data: {
          ...data,
          access_token: Taro.getStorageSync("access_token") || null,
          user_id: Taro.getStorageSync("user_id") || null
        },
        header: {
          "content-type": "application/x-www-form-urlencoded"
        },
        success(res) {
          if (res.data.res === 1004) {
            Taro.reLaunch({
              url: "/pages/login/index"
            });
          } else {
            resolve(res.data);
          }
        }
      });
    });
  }
};

export default http;
